import request from './request'

// ==================== 用户管理 ====================

/**
 * 获取用户列表
 */
export const getUserList = (params) => {
  return request({
    url: '/system/users/',
    method: 'get',
    params
  })
}

/**
 * 创建用户
 */
export const createUser = (data) => {
  return request({
    url: '/system/users/',
    method: 'post',
    data
  })
}

/**
 * 更新用户
 */
export const updateUser = (id, data) => {
  return request({
    url: `/system/users/${id}/`,
    method: 'put',
    data
  })
}

/**
 * 删除用户
 */
export const deleteUser = (id) => {
  return request({
    url: `/system/users/${id}/`,
    method: 'delete'
  })
}

/**
 * 切换用户状态
 */
export const toggleUserStatus = (id) => {
  return request({
    url: `/system/users/${id}/toggle_status/`,
    method: 'post'
  })
}

/**
 * 重置用户密码
 */
export const resetUserPassword = (id, password) => {
  return request({
    url: `/system/users/${id}/reset_password/`,
    method: 'post',
    data: { password }
  })
}

// ==================== 角色管理 ====================

/**
 * 获取角色列表
 */
export const getRoleList = (params) => {
  return request({
    url: '/system/roles/',
    method: 'get',
    params
  })
}

/**
 * 创建角色
 */
export const createRole = (data) => {
  return request({
    url: '/system/roles/',
    method: 'post',
    data
  })
}

/**
 * 更新角色
 */
export const updateRole = (id, data) => {
  return request({
    url: `/system/roles/${id}/`,
    method: 'put',
    data
  })
}

/**
 * 删除角色
 */
export const deleteRole = (id) => {
  return request({
    url: `/system/roles/${id}/`,
    method: 'delete'
  })
}

// ==================== 系统配置 ====================

/**
 * 获取配置列表
 */
export const getConfigList = (params) => {
  return request({
    url: '/system/configs/',
    method: 'get',
    params
  })
}

/**
 * 获取配置类型列表
 */
export const getConfigTypes = () => {
  return request({
    url: '/system/configs/types/',
    method: 'get'
  })
}

/**
 * 创建配置
 */
export const createConfig = (data) => {
  return request({
    url: '/system/configs/',
    method: 'post',
    data
  })
}

/**
 * 更新配置
 */
export const updateConfig = (id, data) => {
  return request({
    url: `/system/configs/${id}/`,
    method: 'put',
    data
  })
}

/**
 * 删除配置
 */
export const deleteConfig = (id) => {
  return request({
    url: `/system/configs/${id}/`,
    method: 'delete'
  })
}

// ==================== 操作日志 ====================

/**
 * 获取日志列表
 */
export const getLogList = (params) => {
  return request({
    url: '/system/logs/',
    method: 'get',
    params
  })
}

/**
 * 获取日志类型列表
 */
export const getLogTypes = () => {
  return request({
    url: '/system/logs/types/',
    method: 'get'
  })
}

/**
 * 获取日志统计信息
 */
export const getLogStats = () => {
  return request({
    url: '/system/logs/stats/',
    method: 'get'
  })
}

